package oocl.custormer.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oocl.custormer.dao.FoodDao;
import oocl.custormer.po.Food;
import oocl.custormer.util.DbUtil;

public class FoodDaoImpl implements FoodDao{
	public List<Food> findAllFood(int mId) {
		List<Food> f = new ArrayList<Food>();
		String sql = "select * from Food where mId=?";
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		con = DbUtil.connect();
		try {
			pst = con.prepareStatement(sql);
			pst.setInt(1, mId);
			rs = pst.executeQuery();
			System.out.println(rs);
			while (rs.next()) {
				int fId = rs.getInt("fId");
				String fName = rs.getString("fName");
				double fPrice= rs.getDouble("fPrice");
				String fViewPath = rs.getString("fViewPath");
				Food ff = new Food(fId,fName,mId,fPrice,fViewPath);
				f.add(ff);
			}
		} catch (SQLException e) {

			e.printStackTrace();
		} finally {
			DbUtil.free(con, pst, null);
		}
		return f;
	}

}
